package com.homework;

import java.awt.*;
import java.util.Scanner;

/**
 * @author xiyu
 * @version 1.0
 * @date 2025/3/29 18:29
 * @description
 */
public class T4 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.print("请输入验证码的位数：");
        int count = input.nextInt();
        String vcode = genVCode(count);
        System.out.println("vcode = " + vcode);

        System.out.println("请输入4位验证码：");
        String inputvc = input.next();
        if (vcode.equals(inputvc)){
            System.out.println("验证成功");
        }else {
            System.err.println("验证失败");
        }


    }
    public static String genVCode(int count){
        
        String vcode = "";
        for (int i = 0; i < count; i++) {
            int m = (int) (Math.random()*(3-1+1))+1;
            int m1 = (int) (Math.random()*(57-48+1))+48;
            int m2 = (int) (Math.random()*(122-97+1))+97;
            int m3 = (int) (Math.random()*(90-65+1))+65;
            switch (m){
                case 1:
                    char m11 = (char) m1;
                    vcode = vcode+m11;
                    break;
                case 2:
                    char m22 = (char) m2;
                    vcode = vcode+m22;
                    break;
                case 3:
                    char m33 = (char) m3;
                    vcode = vcode+m33;
                    break;
            }
        }
        return vcode;
    }
}
